<div class="container">

    <div class="page-header">
        <div class="row">
            <h1 class="span8"><?= ucfirst($post_type) ?> : View All</h1>
            <span class="span4 clearfix">
                <a class="nav-control new-page w-18" href="<?= base_url('posts/view_edit?post_type=' . $post_type . '&post_action=NEW') ?>">
                    Add <?= ucfirst($post_type) ?>
                </a>
            </span>
        </div>


    </div>

    <div class="row">

        <div class="span12">

            <table class="table table-striped table-bordered table-condensed">
                <thead>
                    <tr>
                        <th>Title</th>
                        <th>Status</th>
                        <th>Date</th>
                        <th class="th-action center">Action</th>
                    </tr>
                </thead>
                <tbody>

                    <?
                    $_GET['_cur_level'] = 0;

                    function parents_finder ($parent_ID = 0){

                    $CI = & get_instance ();

                    $myPosts = $CI->posts_model->view_all_children($parent_ID,$_GET['post_type']);
                    $myPosts = $CI->translate->res_array($myPosts, $CI->activeLang);

                    foreach ($myPosts as $onePost):

                    $cur_ID = $onePost['ID'];

                    ?>
                    <tr>
                        <td>
                            <a href="<?= base_url() ?>posts/view_edit?post_ID=<?= $cur_ID ?>&post_type=<?= $_GET['post_type'] ?>&post_action=EDIT">
                                <?= repeat_sign('&nbsp;', $_GET['_cur_level'] * 3) . '- ' . $onePost['post_title'] ?>
                            </a>
                        </td>

                        <td><?= $onePost['post_status'] ?></td>

                        <td><?= date('d.m.Y / H:i', $onePost['date_time']) ?>h</td>

                        <td class="center">
                            <a href="<?= base_url() ?>posts/view_edit?post_ID=<?= $cur_ID ?>&post_type=<?= $_GET['post_type'] ?>&post_action=EDIT"><i class="icon-pencil"></i> Edit</a> |
                            <a href="<?= base_url() ?>posts/delete/<?= $cur_ID ?>?post_type=<?= $_GET['post_type'] ?>" class="delete_post"><i class="icon-trash"></i> Delete</a>

                        </td>

                    </tr>
                    <?

                    if (count($CI->posts_model->view_all_children($cur_ID, $_GET['post_type'])) > 0) :
                    $_GET['_cur_level'] +=1;
                    parents_finder($cur_ID);
                    endif;

                    endforeach;
                    
                    $_GET['_cur_level'] --;

                    }

                    ?>


                    <?= parents_finder(0); unset($_GET['_cur_level']); ?>

                </tbody>
            </table>

        </div>

    </div>

</div> <!-- /container -->